<!DOCTYPE html>
<html lang="zh">

<head>
	<th:block th:include="include :: header('统计分析设置')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 组织机构
				</div>
				<div class="box-tools pull-right">
					<!-- <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i
							class="fa fa-edit"></i></a> -->
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
							class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
							class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i
							class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="deptId" name="deptId">
						<input type="hidden" id="parentId" name="parentId">
						<div class="select-list">
							<ul>
								<li>
									<label style="width: 80px;">作业区名称:</label>
									<input type="text" name="zyqName" placeholder="请输入作业区名称" />
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
											class="fa fa-search"></i>&nbsp;搜索</a>
									<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
											class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>

				<div class="btn-group-sm" id="toolbar" role="group">

				</div>
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>

	<!-- 修改频率 -->
	<div class="modal " id="edit-scene-dialog" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated flipInY">

				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><span
							aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title">修改频率</h4>
				</div>

				<div class="modal-body">
					<!-- <input type="hidden" name="sceneId" id="current-scene-id" value="" /> -->
					<form class="form-horizontal m" id="form-frequency-edit">
						<input name="id" type="hidden" id="Id">
						<div class="form-group">
							<label class="col-sm-3 control-label">频率 秒:</label>
							<div class="col-sm-8">
								<input name="frequency" id="frequency" class="form-control" type="text" required>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" onclick="submitEditScene()">保存</button>
				</div>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:frequency:edit') }]];
		$(function () {
			var panehHidden = false;
			if ($(this).width() < 769) {
				panehHidden = true;
			}
			$('body').layout({ initClosed: panehHidden, west__size: 185 });
			// 回到顶部绑定
			if ($.fn.toTop !== undefined) {
				var opt = {
					win: $('.ui-layout-center'),
					doc: $('.ui-layout-center')
				};
				$('#scroll-up').toTop(opt);
			}
			queryUserList();
			queryDeptTree();

		});

		function queryDeptTree() {
			var url = "/gzmx_scdw/gzmx_scdw/basicTreeData";
			var options = {
				url: url,
				expandLevel: 2,
				onClick: zOnClick,
			};
			console.log(options, 'options');
			// console.log($.tree);
			let ab = $.tree.init(options);
			console.log(ab, 'ab');

			function zOnClick(event, treeId, treeNode) {
				$("#deptId").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
				$.table.search();
			}
		}

		function queryUserList() {
			var options = {
				url: '/youtian/frequency/list',
				createUrl: '/page-route-new/template-management/add',
				updateUrl: '/page-route-new/analysis-frequency-set/edit/{id}',
				// updateUrl: '/page-route-new/template-management/edit',
				// removeUrl: "/youtian/template/delete/{id}",
				// exportUrl: prefix + "/export",
				// importUrl: prefix + "/importData",
				// importTemplateUrl: prefix + "/importTemplate",
				sortName: "createTime",
				sortOrder: "desc",
				modalName: "频率",
				columns: [{
					checkbox: true
				},
				{
					field: 'id',
					title: 'ID',
					visible: false
				},
				{
					field: 'dwmc',
					title: '点位名称'
				},
				{
					field: 'jb',
					title: '级别'
				},

				{
					field: 'ejdwName',
					title: '二级单位名称'
				},
				{
					field: 'zyqName',
					title: '作业区名称'
				},
				{
					visible: editFlag == 'hidden' ? false : true,
					title: '开关状态',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},
				{
					field: 'frequency',
					title: '频率 秒'
				},
				{
					title: '操作',
					align: 'center',
					formatter: function (value, row, index) {
						console.log(row);
						// if (row.userId != 1) {
						var actions = [];
						// actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push(`<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit('${row.id}')"><i class="fa fa-edit"></i>编辑</a> `);
						return actions.join('');
						// } else {
						//     return "";
						// }
					}
				}]
			};
			$.table.init(options);
		}

		$('#btnExpand').click(function () {
			$._tree.expandAll(true);
			$(this).hide();
			$('#btnCollapse').show();
		});

		$('#btnCollapse').click(function () {
			$._tree.expandAll(false);
			$(this).hide();
			$('#btnExpand').show();
		});

		$('#btnRefresh').click(function () {
			queryDeptTree();
		});

		//修改频率
		function edit(row) {
			var row = row.split(',')
			$('#Id').val(row[0])
			$('#edit-scene-dialog').modal('show');
		}

		//修改提交
		function submitEditScene() {
            if ($.validate.form()) {
                $.operate.save('/youtian/frequency/edit', $('#form-frequency-edit').serialize());
            }
            $('#edit-scene-dialog').modal('hide');
			$.modal.msg('操作成功')
			$.table.refresh()
        }

		/*发布状态信息显示 */
		function statusTools(row) {
			console.log(row, 11111);
			if (row.switchStatus == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
			}
		}

		/* 用户管理-停用 */
		function disable(id) {
			$.modal.confirm("确认要停用吗？", function () {
				$.operate.post("/youtian/frequency/edit", { "id": id, "switchStatus": 1 });
			})
		}

		/* 用户管理启用 */
		function enable(id) {
			$.modal.confirm("确认要启用吗？", function () {
				$.operate.post("/youtian/frequency/edit", { "id": id, "switchStatus": 0 });
			})
		}
	</script>
</body>

</html>